<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui的样式 -->
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/default/easyui.css">
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- js文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">

$(function(){
	$('#StuList').datagrid({
		url:"findAllRecord", 
		queryParams: {			
			sid:"${currentUser.sid}",
		}
	});
});

$(function(){
	//更改底部工具栏
	var pager = $('#StuList').datagrid('getPager');	
	  pager.pagination({
		pageList: [10,20,30],
	});
});	
/**
//删除课程
function delcourse(){
 //获取课程ID
   var cid = $('#StuList').datagrid('getSelected').cid;
 //发送请求
      window.location.href="delRecord?cid="+cid;
 }
 */
 
//删除课程
 function delcourse(){
	//1.获取被选中需要退选的课程
	 var data = $('#StuList').datagrid('getSelections')
	 if(data.length==0){
			$.messager.show({
				title:'警告',
				msg:'请选中需要退选的课程',
				timeout:1500,
				showType:'slide',
					style:{
						left:100,
						right:'',
						top:100
					}
		  		});
			}else{
				//2.声明一个空的数组	装选中的ID
				var cids=[];
				for (var  i= 0;  i< data.length; i++) {
					cids.push(data[i].cid)			
				}
				$.messager.confirm('确认退选', '您确定要退选这'+data.length+'门课程吗？', function(r){
					if (r){
					    $.ajax({
					    	type:"post",
					    	url:"delRecord",
					    	data:{"cids":cids},
					    	dataType:"text",
					    	success:function(data){
					    		if(data==1){
					    			//提示退选成功
					    			$.messager.alert('提示','退选成功','info',function(){
	  				    				$("#StuList").datagrid('reload');
	  				    			});   
	  				    			
					    		}else{
					    			//提示退选失败
					    			$.messager.alert('提示','退选失败！');
					    			$("#StuList").datagrid('reload');
					    		}
					    	}
					    })
					}else{
						$("#StuList").datagrid('uncheckAll')
					}
				});
		}
 }
 
</script>
<body>
	 <table id="StuList" title="课程记录查询" class="easyui-datagrid" method="post"
            toolbar="#toolbar" pagination="true" fit="true" pageSize="20"  
            striped="true"  
            rownumbers="true" fitColumns="true" border="false">         
        <thead>
            <tr>
                <th field="ck" checkbox="true"></th>               
                <th field="cid" hidden="true">课程ID</th>
                <th field="cname" width="50" resizable="false">课程名字</th>
                <th field="cbtime" width="50" resizable="false">开始时间</th>
                <th field="cetime" width="50" resizable="false">结束时间</th>
                <th field="ccount" width="50" resizable="false">最多选课人数</th>
                <th field="tname" width="50" resizable="false">授课老师</th>
                <th field="sname" width="50" resizable="false">学生名字</th>        
            </tr>
        </thead>
    </table> 
     <div id="toolbar">       
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delcourse()">退选</a>
    </div> 
    
</body>
</html>